<?php

namespace common\models\farmerhouse;

use common\models\business\BusinessUser;
use Yii;

/**
 * This is the model class for table "farmerhouse_comment".
 *
 * @property integer $id
 * @property integer $userid
 * @property integer $houseid
 * @property string $content
 * @property integer $star
 * @property integer $createtime
 * @property integer $status
 */
class FarmerhouseComment extends \yii\db\ActiveRecord
{

    const STATUS_AGREE = 1;
    const STATUS_DISAGREE = -1;
    const STATUS_NOMAL = 0;
    public static $statues = [
        self::STATUS_AGREE => '通过',
        self::STATUS_DISAGREE => '不通过',
        self::STATUS_NOMAL => '未审核',
    ];

    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '农家乐评论',      //用于修改了什么的显示
        'mainfield' => 'content',      //主要的显示标题的字段
        'picturefield' => ['picture'],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>['createtime'],      //不需要记录的字段
    ];


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'farmerhouse_comment';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'userid', 'houseid', 'content', 'star', 'createtime', 'status'], 'required'],
            [['id', 'userid', 'houseid', 'star', 'createtime', 'status'], 'integer'],
            [['content'], 'string', 'max' => 255],
            [['picture'], 'image', 'extensions' => 'jpg, jpeg, gif, png','on' => ['insert', 'update']],
        ];
    }


    public function scenarios()
    {
        $scenarios = parent::scenarios();//本行必填，不写的话就会报如上错误
        $scenarios['create'] = ['picture'];
        $scenarios['update'] = ['picture'];

        return $scenarios;
    }
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'userid' => '评论人',
            'houseid' => '农家乐',
            'content' => '评论内容',
            'star' => '星级',
            'createtime' => '评论时间',
            'status' => '状态',
            'picture' => '评论图'
        ];
    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取评论人
     */
    public function getUser()
    {
        return $this->hasOne(BusinessUser::className(),['id'=>'userid']);
    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取农家乐
     */
    public function getHouse()
    {
        return $this->hasOne(FarmerhouseHouse::className(),['id'=>'houseid']);
    }








}
